package br.com.viamais.util;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
 * Utility class to get messages of resource bundle easily.
 * 
 * TODO: Logger
 * TODO: A utility class to logger.
 * @author eduardo.dev
 */
public final class MessageBundleUtil {
	/**
	 * Resource bundle nick name.
	 */
	private static final String BUNDLE_BASE_NAME = "br.com.viamais.resources.messages";
	/**
	 * Resource bundle.
	 */
	private static ResourceBundle bundle;

	/**
	 * Create a new bundle instance if not exists.
	 * 
	 * @return ResourceBundle: resource bundle.
	 */
	private static ResourceBundle getBundle() {
		if (bundle == null) {
			bundle = ResourceBundle.getBundle(BUNDLE_BASE_NAME);
		}
		return bundle;
	}

	/**
	 * Looking for a message within resource bundle.
	 * 
	 * @param String
	 *            : key.
	 * @return String: value.
	 */
	public static String getValue(String key) {
		String result = null;
		try {
			result = MessageBundleUtil.getBundle().getString(key);
		} catch (MissingResourceException e) {
			result = "??? " + key + " ??? not found!";
		}
		return result;
	}
}
